package com.tstudy.laoshibang.db;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
import com.tstudy.laoshibang.base.BaseApplication;
import com.tstudy.laoshibang.utils.LogUtil;

public class DaoFactory {
	DBHelper dbHelper = null;
	private static DaoFactory instance = new DaoFactory();

	private DaoFactory() {
		getHelper();

	}

	public static DaoFactory getInstance() {
		return instance;
	}

	/**
	 * 
	 * @Title: getHelper
	 * @Description: TODO(获得DBHelper)
	 * @return 设定文件
	 * @return DBHelper 返回类型
	 * 
	 * 
	 * 10-15 18:17:08.900: W/dalvikvm(26197): Exception Ljava/lang/IllegalStateException; thrown while initializing Lcom/weico/plus/db/DaoFactory;
	 */
	public DBHelper getHelper() {
		LogUtil.d("gethelper dbhelper== " + dbHelper);
		if (dbHelper == null) {
			dbHelper = OpenHelperManager.getHelper(BaseApplication.mContext, DBHelper.class);
			LogUtil.d("gethelper init dbhelper finish ");
		}
		return dbHelper;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public  Dao<?, ?> getDao(Class clazz) {
		try {
			return dbHelper.getDao(clazz);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.d("getDao" + e.getMessage());
			e.printStackTrace();
		}
		return null;
	}

}
